package com.example.spring.boot.rabbitmq.controller;

import com.example.spring.boot.rabbitmq.constant.TopicExchangeConstant;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * TopicExchangeController
 * </p>
 *
 * @author weixin
 * @date 2023/3/28 14:43
 */
@RestController
@RequestMapping("/topic/")
public class TopicExchangeController {

    private final RabbitTemplate rabbitTemplate;

    public TopicExchangeController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @GetMapping("sendTopic")
    public String sendTopic() {
        rabbitTemplate.convertAndSend(TopicExchangeConstant.TOPIC_EXCHANGE, "topic.1", "发送一条测试消息：topic");
        return "topic消息发送成功！！";
    }

}
